package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.CommonParameter;
import com.cskaoyan.bean.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;

/**
 * 接收key=value形式的请求参数
 * @author stone
 * @date 2022/12/23 14:28
 */
@RequestMapping("user")
@RestController// = @Controller + @ResponseBody
public class UserController {

    //localhost:8080/user/register1?username=songge&password=niupi&age=40
    @RequestMapping("register1")
    public BaseRespVo register1(String username,String password,String age) {
        System.out.println("username = " + username);
        System.out.println("password = " + password);
        System.out.println("age = " + age);
        return BaseRespVo.ok();
    }
    //localhost:8080/user/register2?username=songge&password=niupi&age=40
    @RequestMapping("register2")
    //public BaseRespVo register2(String username,String password,int age) {
    public BaseRespVo register2(String username,String password,Integer age) {
        System.out.println("username = " + username);
        System.out.println("password = " + password);
        System.out.println("age = " + age);
        return BaseRespVo.ok();
    }

    //localhost:8080/user/register3?username=songge&password=niupi&age=30&birthday=2022/06/21
    @RequestMapping("register3")
    public BaseRespVo register3(String username, String password, Integer age,
                                Date birthday) {
        System.out.println("birthday = " + birthday);
        return BaseRespVo.ok();
    }
    //localhost:8080/user/register4?username=songge&password=niupi&age=30&birthday=2022-06-21
    @RequestMapping("register4")
    public BaseRespVo register4(String username,String password,Integer age,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        System.out.println("birthday = " + birthday);
        return BaseRespVo.ok();
    }
    //localhost:8080/user/register5?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap&ids=1&ids=2&ids=3
    @RequestMapping("register5")
    public BaseRespVo register5(String username,String password,Integer age,
                                String[] hobbies,Integer[] ids) {
        //String[] hobbies = request.getParameterValues("hobbies");
        System.out.println("hobbies = " + Arrays.asList(hobbies));
        System.out.println("ids = " + Arrays.asList(ids));
        return BaseRespVo.ok();
    }

    //localhost:8080/user/register6?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap&ids=1&ids=2&ids=3
    // &birthday=2022-06-21
    /*@RequestMapping("register6")
    public BaseRespVo register6(String username,String password,Integer age,
                                String[] hobbies,Integer[] ids,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        return BaseRespVo.ok();
    }*/
    @RequestMapping("register6")
    public BaseRespVo register6(User user) {
        System.out.println("user = " + user);
        return BaseRespVo.ok();
    }

    //localhost:8080/user/query?username=song&sort=add_time&order=asc&page=1&limit=10
    @RequestMapping("query")
    public BaseRespVo query(String username, CommonParameter commonParameter) {
        return BaseRespVo.ok();
    }


}
